﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
using Verse.AI;
using Verse.Sound;

namespace Miao.Stand
{
    public class Radius20EmeraldSprayAbility : StandAbilityContinue
    {
        public override bool Continue { get => command_StandAction.useContinue; set => command_StandAction.useContinue = value; }

        public Radius20EmeraldSprayAbility(StandPawn stand) : base(stand)
        {
            
        }
        Command_StandAction command_StandAction;
        public override void Init()
        {
            base.Init();
            //OnContinueEnd=() => (stand as HeirophantGreenStand).UseRadius20EmeraldSpray = false;
            command_StandAction = new Command_StandAction(this);
            SetDefField(command_StandAction);
            command_StandAction.order = 20;
            command_StandAction.onHover =()=> GenDraw.DrawRadiusRing(stand.Position, 20, UnityEngine.Color.green); ;

            command_StandAction.action = () =>
              {
                  if (!Continue)
                  {
                      StartCast();
                      Continue = true;
                      StandSoundDefOf.Radius20EmeraldSpray.PlayOneShot(new TargetInfo(stand));
                      Job job = JobMaker.MakeJob(StandJobDefOf.Radius20EmeraldSpray);

                      stand.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                  }
                  else
                  {
                      stand.jobs.StopAll();
                      Continue = false;
                  }
              };
        }


        
        public override Gizmo DrawGizmo()
        {
            if (!Continue)
            {
                bool disabled = PowerCostEnough(command_StandAction) & CooldownComplete(command_StandAction) & GhostFollow(command_StandAction);
                command_StandAction.disabled = !disabled;
            }
            return command_StandAction;
        }
    }
}
